package com.jinghao.ctws.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.jinghao.core.common.service.impl.JingHaoBaseServiceImpl;
import com.jinghao.core.common.util.cnd.JhCnd;
import com.jinghao.ctws.entity.CwvDataTotal;
import com.jinghao.ctws.entity.CwvPallet;
import com.jinghao.ctws.service.ICwvDataTotalService;
import com.jinghao.ctws.service.ICwvPalletService;

@Service("cwvDataTotalService")
public class CwvDataTotalServiceImpl extends JingHaoBaseServiceImpl<CwvDataTotal> implements ICwvDataTotalService {


	//==================定制内容开始======================
	@Resource
	public ICwvPalletService cwvPalletService;
//在这里修改代码
	@Override
	public void listCwvDataTotalTj(CwvDataTotal model) {
		JhCnd cnd=new JhCnd();
		cnd.append("1=1");
		if(model.getStrMap()!=null){
			Map<String,String> map=model.getStrMap();
			if(map.get("jhorgUuid")!=null&&!map.get("jhorgUuid").toString().trim().equals("")){
				cnd.append(" and JHORG_UUID='"+map.get("jhorgUuid").toString()+"'");
			}
			if(map.get("start")!=null&&!map.get("start").toString().trim().equals("")&&map.get("end")!=null&&!map.get("end").toString().trim().equals("")){
				cnd.append(" and (DATE_FORMAT(b.data_Time, '%Y-%m-%d')>='"+map.get("start").toString()+"' and DATE_FORMAT(b.data_Time, '%Y-%m-%d')<='"+map.get("end").toString()+"')");
			}
			if(map.get("start")!=null&&!map.get("start").toString().trim().equals("")&&(map.get("end")==null||!map.get("end").toString().trim().equals(""))){
				cnd.append(" and DATE_FORMAT(b.data_Time, '%Y-%m-%d')>='"+map.get("start").toString()+"'");
			}
			if(map.get("end")!=null&&!map.get("end").toString().trim().equals("")&&(map.get("start")==null||!map.get("start").toString().trim().equals(""))){
				cnd.append(" and DATE_FORMAT(b.data_Time, '%Y-%m-%d')<='"+map.get("end").toString()+"'");
			}
		}
		List<Map<String,Object>> resultList=new ArrayList<Map<String,Object>>();
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("count", this.getCwvDataTotalHuiZong(model));
		
		model.setJhCnd(cnd);
		List<Map<String,Object>> list=this.queryMapListById(model,"queryMapListTongJi");
		map.put("list", list);
		resultList.add(map);
		model.setMapList(resultList);
	}
 
	public Map<String,Object> getCwvDataTotalHuiZong(CwvDataTotal model) {
		JhCnd cnd=new JhCnd();
		cnd.append("1=1");
		Map<String,String> map=model.getStrMap();
		if(model.getStrMap()!=null){
			if(map.get("jhorgUuid")!=null&&!map.get("jhorgUuid").toString().trim().equals("")){
				cnd.append(" and FJHORG_UUID in (select JHORG_UUID from SYS_ORGANIZATION where JHORG_UUID='"+map.get("jhorgUuid").toString()+"')");
			}
			if(map.get("start")!=null&&!map.get("start").toString().trim().equals("")&&map.get("end")!=null&&!map.get("end").toString().trim().equals("")){
				cnd.append(" and (DATE_FORMAT(data_Time, '%Y-%m-%d')>='"+map.get("start").toString()+"' and DATE_FORMAT(data_Time, '%Y-%m-%d')<='"+map.get("end").toString()+"')");
			}
			if(map.get("start")!=null&&!map.get("start").toString().trim().equals("")&&(map.get("end")==null||map.get("end").toString().trim().equals(""))){
				cnd.append(" and DATE_FORMAT(data_Time, '%Y-%m-%d')>='"+map.get("start").toString()+"'");
			}
			if(map.get("end")!=null&&!map.get("end").toString().trim().equals("")&&(map.get("start")==null||map.get("start").toString().trim().equals(""))){
				cnd.append(" and DATE_FORMAT(data_Time, '%Y-%m-%d')<='"+map.get("end").toString()+"'");
			}
		}
		model.setJhCnd(cnd);
		List<Map<String,Object>> list=this.queryMapListById(model,"queryMapListTongHuiZong");
		Map<String,Object> tempMap=null;
		if(list!=null&&list.size()>0){
			tempMap=list.get(0);
			if(null==tempMap){
				tempMap=new HashMap<String,Object>();
				tempMap.put("dataNumber", 0);
			}
		}else{
			tempMap=new HashMap<String,Object>();
			tempMap.put("dataNumber", 0);
		}
		CwvPallet pallet=new CwvPallet();
		cnd.reset();
		cnd.append("1=1");
		if(model.getStrMap()!=null){
			if(map.get("jhorgUuid")!=null&&!map.get("jhorgUuid").toString().trim().equals("")){
				cnd.append(" and FJHORG_UUID in (select JHORG_UUID from SYS_ORGANIZATION where JHORG_UUID='"+map.get("jhorgUuid").toString()+"')");
			}
			if(map.get("start")!=null&&!map.get("start").toString().trim().equals("")&&map.get("end")!=null&&!map.get("end").toString().trim().equals("")){
				cnd.append(" and (DATE_FORMAT(create_time, '%Y-%m-%d')>='"+map.get("start").toString()+"' and DATE_FORMAT(create_time, '%Y-%m-%d')<='"+map.get("end").toString()+"')");
			}
			if(map.get("start")!=null&&!map.get("start").toString().trim().equals("")&&(map.get("end")==null||map.get("end").toString().trim().equals(""))){
				cnd.append(" and DATE_FORMAT(create_time, '%Y-%m-%d')>='"+map.get("start").toString()+"'");
			}
			if(map.get("end")!=null&&!map.get("end").toString().trim().equals("")&&(map.get("start")==null||map.get("start").toString().trim().equals(""))){
				cnd.append(" and DATE_FORMAT(create_time, '%Y-%m-%d')<='"+map.get("end").toString()+"'");
			}
		}
		pallet.setJhCnd(cnd);
		List<Map<String,Object>> cloudList=this.cwvPalletService.queryMapListById(pallet,"queryMapListTongHuiZong");
		if(cloudList!=null&&cloudList.size()>0){
			tempMap.put("cloudNub", cloudList.get(0).get("cloudNub"));
		}else{
			tempMap.put("cloudNub", 0);
		}
		return tempMap;
	}
	
	@Override
	public void listCwvDataTotalHuiZong(CwvDataTotal model) {
		JhCnd cnd=new JhCnd();
		cnd.append("1=1");
		Map<String,String> map=model.getStrMap();
		if(model.getStrMap()!=null){
			if(map.get("jhorgUuid")!=null&&!map.get("jhorgUuid").toString().trim().equals("")){
				cnd.append(" and FJHORG_UUID in (select JHORG_UUID from SYS_ORGANIZATION where JHORG_UUID='"+map.get("jhorgFullName").toString()+"')");
			}
			if(map.get("start")!=null&&!map.get("start").toString().trim().equals("")&&map.get("end")!=null&&!map.get("end").toString().trim().equals("")){
				cnd.append(" and (DATE_FORMAT(data_Time, '%Y-%m-%d')>='"+map.get("start").toString()+"' and DATE_FORMAT(data_Time, '%Y-%m-%d')<='"+map.get("end").toString()+"')");
			}
			if(map.get("start")!=null&&!map.get("start").toString().trim().equals("")&&(map.get("end")==null||!map.get("end").toString().trim().equals(""))){
				cnd.append(" and DATE_FORMAT(data_Time, '%Y-%m-%d')>='"+map.get("start").toString()+"'");
			}
			if(map.get("end")!=null&&!map.get("end").toString().trim().equals("")&&(map.get("start")==null||!map.get("start").toString().trim().equals(""))){
				cnd.append(" and DATE_FORMAT(data_Time, '%Y-%m-%d')<='"+map.get("end").toString()+"'");
			}
		}
		model.setJhCnd(cnd);
		List<Map<String,Object>> list=this.queryMapListById(model,"queryMapListTongHuiZong");
		Map<String,Object> tempMap=null;
		if(list!=null&&list.size()>0){
			tempMap=list.get(0);
		}else{
			list=new ArrayList<Map<String,Object>>();
			tempMap=new HashMap<String,Object>();
			tempMap.put("dataNumber", 0);
			list.add(tempMap);
		}
		CwvPallet pallet=new CwvPallet();
		cnd.reset();
		cnd.append("1=1");
		if(model.getStrMap()!=null){
			if(map.get("jhorgUuid")!=null&&!map.get("jhorgUuid").toString().trim().equals("")){
				cnd.append(" and FJHORG_UUID in (select JHORG_UUID from SYS_ORGANIZATION where JHORG_UUID='"+map.get("jhorgFullName").toString()+"')");
			}
			if(map.get("start")!=null&&!map.get("start").toString().trim().equals("")&&map.get("end")!=null&&!map.get("end").toString().trim().equals("")){
				cnd.append(" and (DATE_FORMAT(create_time, '%Y-%m-%d')>='"+map.get("start").toString()+"' and DATE_FORMAT(create_time, '%Y-%m-%d')<='"+map.get("end").toString()+"')");
			}
			if(map.get("start")!=null&&!map.get("start").toString().trim().equals("")&&(map.get("end")==null||!map.get("end").toString().trim().equals(""))){
				cnd.append(" and DATE_FORMAT(create_time, '%Y-%m-%d')>='"+map.get("start").toString()+"'");
			}
			if(map.get("end")!=null&&!map.get("end").toString().trim().equals("")&&(map.get("start")==null||!map.get("start").toString().trim().equals(""))){
				cnd.append(" and DATE_FORMAT(create_time, '%Y-%m-%d')<='"+map.get("end").toString()+"'");
			}
		}
		List<Map<String,Object>> cloudList=this.cwvPalletService.queryMapListById(pallet,"queryMapListTongHuiZong");
		if(cloudList!=null&&cloudList.size()>0){
			tempMap.put("cloudNub", cloudList.get(0).get("cloudNub"));
		}else{
			tempMap.put("cloudNub", 0);
		}
		model.setMapList(list);
	}
	//==================定制内容结束======================
}
